package com.kws.merchant.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.kws.common.core.domain.R;
import com.kws.merchant.domain.Merchant;
import com.kws.merchant.domain.Order;
import com.kws.merchant.domain.po.*;
import com.kws.merchant.domain.vo.*;
import com.kws.merchant.service.AttentionService;
import com.kws.merchant.service.GoodsService;
import com.kws.merchant.service.ShopCartService;
import com.kws.merchant.service.UserOrderService;
import com.kws.system.api.domain.SysDictData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * @author : zhangbenting
 * @date : 2024/11/20 14:10
 * @Version: 1.0
 */
@RequestMapping("/userShop")
@RestController
@Api(value = "用户服务-商店", tags = "用户服务-商店")
public class UserShopController {

    @Autowired
    private GoodsService goodsService;

    @Autowired
    private ShopCartService shopCartService;

    @Autowired
    private AttentionService attentionService;

    @Autowired
    private UserOrderService userOrderService;

    @PostMapping("/getVideoNumberDevice")
    @ApiOperation("获取视频号设备商")
    public R<List<MerchantDetailVo>> getVideoNumberDevice() {
        return R.ok(goodsService.getVideoNumberDevice());
    }

    @PostMapping("/goodsList")
    @ApiOperation("获取商品列表")
    @ApiOperationSupport(order = 1, includeParameters = {
            "goodsPo.goodsName",
            "goodsPo.type",
            "goodsPo.shopsName",
            "goodsPo.shopsId",
            "goodsPo.deviceTag",
            "goodsPo.pageSize",
            "goodsPo.totalPage"
    })
    public R<Page<GoodsVo>> goodsList(@RequestBody GoodsPo goodsPo) {
        return R.ok(goodsService.goodsList(goodsPo));
    }

    @PostMapping("/getGoodsInfo")
    @ApiOperation("获取商品信息")
    @ApiOperationSupport(order = 1, includeParameters = {
            "goodsPo.goodsId"
    })
    public R<GoodsInfoVo> getGoodsInfo(@RequestBody GoodsPo goodsPo) {
        return R.ok(goodsService.getGoodsInfo(goodsPo));
    }

    @PostMapping("/getMerchantDetail")
    @ApiOperation("获取店铺详情")
    @ApiOperationSupport(order = 1, includeParameters = {
            "goodsPo.shopsId"
    })
    public R<MerchantDetailVo> getMerchantDetail(@RequestBody GoodsPo goodsPo) {
        return R.ok(goodsService.getMerchantDetail(goodsPo.getShopsId()));
    }

    @PostMapping("/getDictInfo")
    @ApiOperation("获取字典信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dictType", value = "字典类型", dataType = "String", required = true),
    })
    public R<List<SysDictData>> getDictInfo(@RequestParam String dictType) {
        return R.ok(goodsService.getDictInfo(dictType));
    }

    @GetMapping("merchantLicense")
    @ApiOperation("商家证照信息")
    public R<MerchantLicenseVo> merchantLicense(@RequestParam Long shopsId) {
        return R.ok(goodsService.merchantLicense(shopsId));
    }

    @ApiOperation("获取购物车信息列表")
    @PostMapping("/getShopCartList")
    @ApiOperationSupport(order = 1, includeParameters = {
            "shopCartPo.goodsType",
            "shopCartPo.pageSize",
            "shopCartPo.totalPage"
    })
    public R<Page<ShopCartVo>> getShopCartList(@RequestBody ShopCartPo shopCartPo) {
        return R.ok(shopCartService.getShopCartList(shopCartPo));
    }

    @ApiOperation("商品添加购物车")
    @PostMapping("/addShopCartGoods")
    @ApiOperationSupport(order = 2, includeParameters = {
            "shopCartPo.goodsId",
            "shopCartPo.specificationId",
            "shopCartPo.goodsCount",
            "shopCartPo.goodsType"
    })
    public R<Boolean> addShopCartGoods(@RequestBody ShopCartPo shopCartPo) {
        return R.ok(shopCartService.addShopCartGoods(shopCartPo));
    }

    @PostMapping("/removeShopCartGoods")
    @ApiOperation("删除购物车商品")
    @ApiOperationSupport(order = 2, includeParameters = {
            "shopCartPo.shopsIds"
    })
    public R<Boolean> removeShopCartGoods(@RequestBody ShopCartPo shopCartPo) {
        return R.ok(shopCartService.removeBatchByIds(shopCartPo.getShopsIds()));
    }

    @PostMapping("/getConfirmOrder")
    @ApiOperation(value = "根据设备商品信息生成确认单(立即购买)")
    @ApiOperationSupport(order = 1, includeParameters = {
            "confirmGoodsVo.goodsId",
            "confirmGoodsVo.specificationId",
            "confirmGoodsVo.goodsCount"
    })
    public R<ConfirmOrderVo> getConfirmOrder(@RequestBody ConfirmGoodsVo confirmGoodsVo) {
        return R.ok(userOrderService.getConfirmOrder(confirmGoodsVo));
    }

    @PostMapping("/addUserOrder")
    @ApiOperation(value = "新增商品订单")
    @ApiOperationSupport(order = 2, includeParameters = {
            "userOrderPo.confirmGoodsPoList.goodsId",
            "userOrderPo.confirmGoodsPoList.merchantId",
            "userOrderPo.confirmGoodsPoList.goodsCount",
            "userOrderPo.confirmGoodsPoList.specificationId",
            "userOrderPo.confirmGoodsPoList.goodsType",
            "userOrderPo.confirmGoodsPoList.leaveWord",
            "userOrderPo.memberReceiveAddressId",
            "userOrderPo.stationId",
            "userOrderPo.stationType",
            "userOrderPo.payWay",
            "userOrderPo.payType"
    })
    public R<List<Order>> addUserOrder(@RequestBody UserOrderPo userOrderPo) {
        return R.ok(userOrderService.addUserOrder(userOrderPo));
    }

    @PostMapping("getShopCarConfirmOrder")
    @ApiOperation("根据购物车信息生成设备确认单")
    @ApiOperationSupport(order = 3, includeParameters = {
            "shopCartPo.shopsIds"
    })
    public R<ConfirmOrderVo> getShopCarConfirmOrder(@RequestBody ShopCartPo shopCartPo) {
        return R.ok(userOrderService.getShopCarConfirmOrder(shopCartPo));
    }


    @PostMapping("/getAttentionList")
    @ApiOperation("获取用户店铺关注信息列表")
    @ApiOperationSupport(order = 1, includeParameters = {
            "attentionPo.shopName",
            "attentionPo.pageSize",
            "attentionPo.totalPage"
    })
    public R<Page<AttentionVo>> getAttentionList(@RequestBody AttentionPo attentionPo) {
        return R.ok(attentionService.getAttentionList(attentionPo));
    }

    @PostMapping("/getCollectList")
    @ApiOperation("获取用户商品或服务关注信息列表")
    @ApiOperationSupport(order = 1, includeParameters = {
            "attentionPo.type",
            "attentionPo.pageSize",
            "attentionPo.totalPage"
    })
    public R<Page<GoodsCollectVo>> getCollectList(@RequestBody AttentionPo attentionPo) {
        return R.ok(attentionService.getCollectList(attentionPo));
    }

    @PostMapping("/isAttention")
    @ApiOperation("查看是否被收藏")
    @ApiOperationSupport(order = 1, includeParameters = {
            "attentionPo.attentionTypeIds",
            "attentionPo.type"
    })
    public R<Boolean> isAttention(@RequestBody AttentionPo attentionPo) {
        return R.ok(attentionService.isAttention(attentionPo));
    }


    @PostMapping("/attentionShopCartGoods")
    @ApiOperation("添加关注信息")
    @ApiOperationSupport(order = 1, includeParameters = {
            "attentionPo.attentionTypeIds",
            "attentionPo.type"
    })
    public R<Boolean> attentionShopCartGoods(@RequestBody AttentionPo attentionPo) {
        return R.ok(attentionService.attentionShopCartGoods(attentionPo));
    }

    @PostMapping("/cancelAttentionShopCartGoods")
    @ApiOperation("取消关注信息")
    @ApiOperationSupport(order = 2, includeParameters = {
            "attentionPo.attentionIds",
            "attentionPo.attentionTypeIds",
            "attentionPo.type",
    })
    public R<Boolean> cancelAttentionShopCartGoods(@RequestBody AttentionPo attentionPo) {
        return R.ok(attentionService.cancelAttentionShopCartGoods(attentionPo));
    }

    @PostMapping("updateGoodsView")
    @ApiOperation(value = "新增商品浏览记录时间")
    public R updateGoodsView(@RequestParam("goodsViewId") Long goodsViewId, @RequestParam("time") Long time) {
        return R.ok(attentionService.updateGoodsView(goodsViewId, time));
    }
}
